package io.geekidea.boot.shop.controller.web;

import io.geekidea.boot.auth.annotation.Permission;
import io.geekidea.boot.common.enums.SysLogType;
import io.geekidea.boot.framework.annotation.Log;
import io.geekidea.boot.framework.page.Paging;
import io.geekidea.boot.framework.response.ApiResult;
import io.geekidea.boot.shop.dto.InviteRecordDto;
import io.geekidea.boot.shop.query.web.InviteRecordQuery;
import io.geekidea.boot.shop.service.base.api.InviteRecordService;
import io.geekidea.boot.shop.vo.web.InviteRecordVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 *  控制器
 *
 * @author geekidea
 * @since 2024-10-27
 */
@Slf4j
@RestController
@Tag(name = "")
@RequestMapping("/admin/inviteRecord")
public class InviteRecordController {

    @Autowired
    private InviteRecordService inviteRecordService;

    /**
     * 添加null
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.ADD)
    @Operation(summary = "添加null")
    @PostMapping("/addInviteRecord")
    @Permission("invite:record:add")
    public ApiResult addInviteRecord(@Valid @RequestBody InviteRecordDto dto) {
        log.info("添加null：{}", dto);
        boolean flag = inviteRecordService.addInviteRecord(dto);
        return ApiResult.result(flag);
    }

    /**
     * 修改null
     *
     * @param dto
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.UPDATE)
    @Operation(summary = "修改null")
    @PostMapping("/updateInviteRecord")
    @Permission("invite:record:update")
    public ApiResult updateInviteRecord(@Valid @RequestBody InviteRecordDto dto) {
        log.info("修改null：{}", dto);
        boolean flag = inviteRecordService.updateInviteRecord(dto);
        return ApiResult.result(flag);
    }

    /**
     * 删除null
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Log(type = SysLogType.DELETE)
    @Operation(summary = "删除null")
    @PostMapping("/deleteInviteRecord/{id}")
    @Permission("invite:record:delete")
    public ApiResult deleteInviteRecord(@PathVariable Integer id) {
        log.info("删除null：{}", id);
        boolean flag = inviteRecordService.deleteInviteRecord(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取null详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取null详情")
    @PostMapping("/getInviteRecord/{id}")
    @Permission("invite:record:info")
    public ApiResult<InviteRecordVo> getInviteRecord(@PathVariable Integer id) {
        log.info("获取null详情：{}", id);
        InviteRecordVo inviteRecordVo = inviteRecordService.getInviteRecordById(id);
        return ApiResult.success(inviteRecordVo);
    }

    /**
     * 获取null分页列表
     *
     * @param query
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取null分页列表")
    @PostMapping("/getInviteRecordPage")
    @Permission("invite:record:page")
    public ApiResult<InviteRecordVo> getInviteRecordPage(@Valid @RequestBody InviteRecordQuery query) {
        log.info("获取null分页列表：{}", query);
        Paging<InviteRecordVo> paging = inviteRecordService.getInviteRecordPage(query);
        return ApiResult.success(paging);
    }

}
